package org.lsc.lesson.lesson2.config;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.env.EnvironmentPostProcessor;
import org.springframework.core.env.ConfigurableEnvironment;

import java.util.HashMap;
import java.util.Map;

/**
 * @Author 刘事成
 * @Date 2018/10/11
 * @Time 9:50
 * @Description:研究系列
 */
public class PropertySourceLocator implements EnvironmentPostProcessor {

    @Override
    public void postProcessEnvironment(ConfigurableEnvironment environment, SpringApplication application) {
        //远程获取配置
        //这里我写死了,主要是我不知道怎么去远程拿 哈哈哈哈
        Map<String, String> propertyMap = new HashMap<>();
        propertyMap.put("server.port", "11001");
        propertyMap.put("spring.datasource.driver-class-name", "com.mysql.jdbc.Driver");
        propertyMap.put("spring.datasource.url", "jdbc:mysql://www.txy.com:3306/summer?useUnicode=true&characterEncoding=utf-8&useSSL=false");
        propertyMap.put("spring.datasource.username", "lsc");
        propertyMap.put("spring.datasource.password", "mysql%123");

        PropertySource propertySource = new PropertySource("sys-config",propertyMap);
        environment.getPropertySources().addFirst(propertySource);
    }
}
